<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
if(!isset($_SESSION['adminuserid']))
{
	header("location:index.php?msg=logfirst");
	die();
}

// INSERT into database.
if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit")	{				
	$taxrat = mysql_real_escape_string($_REQUEST['taxrate']);
	$insert="INSERT INTO `tbloptionvalues` (`varoptionvaluename`, `intlanguageid`) VALUES ('$taxrat', '1')";
	$sql=$obj_db->insert($insert);				
	header("location:prodattribute.php?msg=add");
	die();
}

// UPDATE the record
$txrat = "";
$action=1;

if((isset($_REQUEST['a']) && trim($_REQUEST['a'])==2) && (!(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Submit"))) {
 	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid'])!="") {
		$screen_id =  $_REQUEST['intid'];
		$sql = "select * from tbloptionvalues where intid ='$screen_id'";
		$result = $obj_db->select($sql);
		if(count($result)<=0) {
			echo " No Record Found!<br>";
			die();
		}
		
		if($result) {
			foreach($result as $row) {
				$txrat = $row['varoptionvaluename'];				
				$action=2;
			}
		}
		if(isset($_REQUEST['Submit']) && trim($_REQUEST['Submit']) == "Update")	{
			$taxrat = mysql_real_escape_string($_REQUEST['taxrate']);
			$sql_upd ="UPDATE `tbloptionvalues`
			SET `varoptionvaluename` = '$taxrat'
			where intid ='$screen_id'";
			$result = $obj_db->edit($sql_upd);
			$action=1;
			header("location:prodattribute.php?msg=edit");
			die();
		}
	}
}

//DELETE record from database
if(isset($_REQUEST['a']) && trim($_REQUEST['a'])==3) {
	if(isset($_REQUEST['intid']) && trim($_REQUEST['intid']!="")) {	
		$id =  $_REQUEST['intid'];
		$sql= "DELETE FROM `tbloptionvalues` WHERE `intid` ='$id'";
		$query1 = mysql_query($sql);
		$sql1 = "DELETE FROM `tblproductoptions` WHERE `intoptionid` ='$id'";
		$query = mysql_query($sql1);
		header("location:prodattribute.php?msg=del");
		die();
	}
}

?>
<?php include("inc/header.php");?>
<body>
<script language="javascript" src="js/prodattribute.js"></script>
<form name="prodattribute" action="" method="post" enctype="multipart/form-data" >
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="1" class="middlebackground">
  <tr>
    <td colspan="3" valign="top" align="center"><?php include(INC."top.inc.php");?></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>
	
	<?php   
   if(isset($_REQUEST['script']))
	{
	if(trim($_REQUEST['script'])=='addprodattribute' || trim($_REQUEST['script'])=='editprodattribute')
	{
	?>
		
		
      <table width="60%" border="0" align="center" cellpadding="2" cellspacing="2" class="border">
        <tr class="bg1">
          <td colspan="5" align="center"><strong>
            <?php if($_REQUEST['script']=='addprodattribute'){echo "Add New Attribute...";}
	if($_REQUEST['script']=='editprodattribute'){echo "Edit Attribute...";}?>
          </strong></td>
        </tr>
        <tr>
          <td width="4%">&nbsp;</td>
          <td width="26%" align="left">&nbsp;</td>
          <td width="3%">&nbsp;</td>
          <td width="63%" align="right">(* All fields are Required)</td>
          <td width="4%">&nbsp;</td>
        </tr>        
        <tr>
          <td>&nbsp;</td>
          <td align="right" class="sltimg">*Option Name  </td>
          <td>:</td>
          <td align="left"><input name="taxrate" type="text" id="taxrate" value="<?php echo stripslashes($txrat);?>" /></td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td colspan="5" align="left">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="5" align="center"><input name="Submit" type="submit" class="btn" id="Submit" value="<?php echo ($action==2) ? "Update":"Submit"; ?>" onClick="return check();"/></td>
        </tr>
        <tr>
          <td colspan="5" align="center">&nbsp;</td>
        </tr>
      </table>
    <?php
	}
} else {
?>
    
	<table class="border" border="0" align="center" cellpadding="2" cellspacing="2" width="70%">
      <tr class="bg1">
        <td colspan="4" align="left"><strong>Product Attributes...</strong></td>
        <td align="center"><a href="prodattribute.php?script=addprodattribute" class="aa">[NEW]</a></td>
      </tr>
      <tr class="tblbg3">
        <td align="center">Option  Name </td>
        <td align="center"><strong>Option Values</strong></td>
        <td align="center"><strong>Product Attribues</strong></td>
        <!--<td align="center"><strong>Tax Desc</strong></td>-->
        <td align="center"><strong>Edit</strong></td>
        <td align="center"><strong>Delete</strong></td>
      </tr>
      <?php
	  
	  	/**************************************
				PAGING CODE START
		**************************************/
			//$rowperpage=23;
			$tablename="tbloptionvalues";
			$per_page_keywords= "";
			$per_page_sorts="";
			include("system/paging.inc.php");

		/**************************************
				PAGING CODE ENDING
		**************************************/
   		$sql="select * from tbloptionvalues Limit ".($page_no*$row_per_page).",".$row_per_page;
		$result=$obj_db->select($sql);
  		if($result)
		{
   		for($i=0;$i<count($result);$i++)
   		{
            $id=$result[$i]['intid'];
			?>
	  <tr class="<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>" onMouseOver="this.className='Hrhover';"  onmouseout="this.className='<?php echo ($i%2==0)?"Hrnormal":"Hralter"; ?>';">
        <td align="center"><?php echo stripslashes($result[$i]['varoptionvaluename']);?></td>
		<td align="center"><a Title="Click here for Values" href="prodattrdetails.php?intoptionid=<?php echo stripslashes($id);?>" class="aa">Values</a></td>
        <td align="center"><a Title="Click here for Product Attribute" href="prodattr.php?intoptionid=<?php echo stripslashes($id);?>" class="aa">Product Attribute</a></td>
        <td align="center"><a class="link" Title="Click here to Edit" href="prodattribute.php?script=editprodattribute&amp;a=2&amp;intid=<?php echo stripslashes($id); ?>"><img src="images/edit.bmp" border="0"/></a></td>
        <td align="center"><a Title="Click here to Delete" href="prodattribute.php?a=3&amp;intid=<?php echo stripslashes($id); ?>" onClick="return confirm('Are you sure to delete this record?');"><img src="images/delete.bmp" border="0"/></a></td>
      </tr>
      <?php }}?>
      <tr>
        <td colspan="10" align="center"><?php pagindet_atbotttom_page($div_page_no,$page_no,$req_querystr,$total_db_rec,$row_per_page);?></td>
      </tr>
    </table>
    <?php }?>
	</td>
	</td>
  </tr>
  <tr>
    <td colspan="3"><?php include("inc/bottom.php");?></td>
  </tr>
</table>
</form>
</body>
</html>
